package com.example.fbi_text.Acitivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.example.fbi_text.R;
import com.example.fbi_text.views.ProductListFragment;

public class ShoppingActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping);

        // 检查容器是否存在
        View container = findViewById(R.id.fragment_container1);
        if (container == null) {
            Log.e("ACTIVITY", "Fragment container not found!");
            return;
        }

        // 加载商品列表Fragment
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container1, new ProductListFragment())
                    .commit();
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
        if (getSupportFragmentManager().findFragmentById(R.id.fragment_container1) == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragment_container1, new ProductListFragment())
                    .commit();
        }
    }
}
